<template>
    <!-- 给li设置一个类名，控制类名的true和false来让他显示背景色和按钮 -->
    <li :class="isActive? 'active' : '' "  @mouseenter="mouseChange('enter')" @mouseleave="mouseChange('leave')">  
    <label>
      <input type="checkbox" :checked='done' @click='changeRadio(id)'/>
      <span>{{thing}}</span>
    </label>
    <button class="btn btn-danger" @click="deleteList(id)" >删除</button>
  </li>
</template>

<script>
export default {
    name:'Item',
    props:['id','thing','done','changeRadio','deleteList'],
    data(){
      return{
        isActive:false
      }
    },
    methods: {
      mouseChange(type){
        //当移入类型为enter时，全等成立，为true
       this.isActive = type === 'enter'
      }
    },
}
</script>

<style scoped>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}

/* 给li增加一个active类名 */
li.active{
    background-color: rgb(177, 237, 239);
}

li.active button{
    display: block;
}
</style>